package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/27 10:06
 */
public class C35 {


    public static int searchInsert(int[] nums, int target) {
        int l = 0, r = nums.length - 1, m;
        while (l <= r) {
            m = l + ((r - l) >> 1);
            if(nums[m] == target) {
                return m;
            }else if(nums[m] < target) {
                l = m + 1;
            }else {
                r = m - 1;
            }
        }
        return l;
    }


    public static void main(String[] args) {
        int[] nums = {1, 3, 5, 6};
        int target = 2;
        System.out.println(searchInsert(nums, target));
    }

}
